package com.njust.RateMyTray_backend.controller;

import com.njust.RateMyTray_backend.common.Result;
import com.njust.RateMyTray_backend.service.storage.StorageService;
import com.njust.RateMyTray_backend.vo.FileUploadResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/upload")
public class FileUploadController {

    @Autowired
    private StorageService storageService;

    @PostMapping("/avatars")
    public ResponseEntity<Result<FileUploadResponseVO>> uploadAvatar(@RequestParam("file") MultipartFile file) {
        String fileUrl = storageService.store(file, "avatars");
        FileUploadResponseVO response = new FileUploadResponseVO(fileUrl);
        return new ResponseEntity<>(Result.success(201, "头像上传成功", response), HttpStatus.CREATED);
    }

    @PostMapping("/comments")
    public ResponseEntity<Result<FileUploadResponseVO>> uploadCommentImage(@RequestParam("file") MultipartFile file) {
        String fileUrl = storageService.store(file, "comments");
        FileUploadResponseVO response = new FileUploadResponseVO(fileUrl);
        return new ResponseEntity<>(Result.success(201, "评论图片上传成功", response), HttpStatus.CREATED);
    }

    @PostMapping("/dishes")
    public ResponseEntity<Result<FileUploadResponseVO>> uploadDishImage(@RequestParam("file") MultipartFile file) {
        String fileUrl = storageService.store(file, "dishes");
        FileUploadResponseVO response = new FileUploadResponseVO(fileUrl);
        return new ResponseEntity<>(Result.success(201, "菜品图片上传成功", response), HttpStatus.CREATED);
    }

    @PostMapping("/windows")
    public ResponseEntity<Result<FileUploadResponseVO>> uploadWindowImage(@RequestParam("file") MultipartFile file) {
        String fileUrl = storageService.store(file, "windows");
        FileUploadResponseVO response = new FileUploadResponseVO(fileUrl);
        return new ResponseEntity<>(Result.success(201, "窗口图片上传成功", response), HttpStatus.CREATED);
    }
} 